/*
 * Albareth - an action roleplaying game.
 * Copyright (C) 2008 Jens Anuth
 *
 * This program is free software; you can redistribute it and/or
 * modify it under the terms of the GNU General Public License
 * as published by the Free Software Foundation; either version 2
 * of the License, or (at your option) any later version.
 * 
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
 *  02110-1301, USA.
 * 
 * $Id: Teleporter.java 48 2008-05-17 02:04:48Z jens464 $
*/
package albareth.core.entity.item;

import albareth.core.entity.Item;
import albareth.core.entity.Mobile;
import albareth.frontend.Tile;
import albareth.util.Location;

public class Teleporter extends Item implements Cloneable
{
    private boolean _automatic = false;
    private Location _targetLocation;
    
    public Teleporter(String name, Tile tile, Location target)
    {
        super(name, tile);
        _targetLocation = target;
        setActivatable(true);
        setLockedDown(true);
    }

    public Teleporter(String name, Tile tile, Location target, boolean automatic)
    {
        this(name, tile, target);
        _automatic = automatic;
    }

    public Object clone() throws CloneNotSupportedException
    {
        Teleporter clone = (Teleporter)super.clone();
        clone.setTargetLocation(new Location(_targetLocation));
        return clone;  
    }

    public boolean onSteppedOn(Mobile src)
    {
        if (isAutomatic()) {
            return onActivate(src);
        }
        return true;
    }

    public boolean onActivate(Mobile src)
    {
        Location target = getTargetLocation();
        if (target != null) {
            src.moveTo(target);
            return true;
        }
        return false;
        
    }

    public boolean isAutomatic()
    {
        return _automatic;
    }

    public void setAutomatic(boolean automatic)
    {
        _automatic = automatic;
    }

    public Location getTargetLocation()
    {
        return _targetLocation;
    }

    public void setTargetLocation(Location targetLocation)
    {
        _targetLocation = targetLocation;
    }

    public void enchant(int level)
    {
    }

}
